<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Parse string to a field-based time value</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="intldateformatter.islenient.html">« IntlDateFormatter::isLenient</a></li>
      <li style="float: right;"><a href="intldateformatter.parse.html">IntlDateFormatter::parse »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.intldateformatter.html">IntlDateFormatter</a></li>
    <li>Parse string to a field-based time value</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="intldateformatter.localtime" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">IntlDateFormatter::localtime</h1>
  <h1 class="refname">datefmt_localtime</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">IntlDateFormatter::localtime</span> -- <span class="refname">datefmt_localtime</span> &mdash; <span class="dc-title">Parse string to a field-based time value</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-intldateformatter.localtime-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格
  </p>
   <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>IntlDateFormatter::localtime</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$offset</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><span class="type">array</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>datefmt_localtime</strong></span>(<span class="methodparam"><span class="type"><a href="class.intldateformatter.html" class="type IntlDateFormatter">IntlDateFormatter</a></span> <code class="parameter">$formatter</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$offset</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type"><span class="type">array</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Converts string $value to a field-based time value ( an array of various fields), starting at
$parse_pos and consuming as much of the input value as possible.
  </p> 
  </div>


 <div class="refsect1 parameters" id="refsect1-intldateformatter.localtime-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">formatter</code></dt>

     <dd>

      <p class="para">
       The formatter resource      
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">string</code></dt>

     <dd>

      <p class="para">
       string to convert to a time      
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">offset</code></dt>

     <dd>

      <p class="para">
       Position at which to start the parsing in $value (zero-based).
       If no error occurs before $value is consumed, $parse_pos will contain -1
       otherwise it will contain the position at which parsing ended .
       If $parse_pos &gt; strlen($value), the parse fails immediately.  
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

   
 
 <div class="refsect1 returnvalues" id="refsect1-intldateformatter.localtime-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Localtime compatible array of integers  : contains 24 hour clock value in tm_hour field,
    或者在失败时返回 <strong><code>false</code></strong>.
   </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-intldateformatter.localtime-examples">
  <h3 class="title">范例</h3>
   <div class="example" id="example-2446">
    <p><strong>示例 #1 <span class="function"><strong>datefmt_localtime()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$fmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">datefmt_create</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">FULL</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">FULL</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'America/Los_Angeles'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">GREGORIAN<br /></span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">datefmt_localtime</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Wednesday,&nbsp;December&nbsp;31,&nbsp;1969&nbsp;4:00:00&nbsp;PM&nbsp;PT'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">'First&nbsp;parsed&nbsp;output&nbsp;is&nbsp;'</span><span style="color: #007700">;<br />if&nbsp;(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$key&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$key</span><span style="color: #DD0000">&nbsp;:&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #DD0000">&nbsp;,&nbsp;"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
   <div class="example" id="example-2447">
    <p><strong>示例 #2 OO example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fmt&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">FULL</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">FULL</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'America/Los_Angeles'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">IntlDateFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">GREGORIAN<br /></span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">localtime</span><span style="color: #007700">(</span><span style="color: #DD0000">'Wednesday,&nbsp;December&nbsp;31,&nbsp;1969&nbsp;4:00:00&nbsp;PM&nbsp;PT'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">'First&nbsp;parsed&nbsp;output&nbsp;is&nbsp;'</span><span style="color: #007700">;<br />if&nbsp;(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$key&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$key</span><span style="color: #DD0000">&nbsp;:&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #DD0000">&nbsp;,&nbsp;"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
     <p class="para">以上例程会输出：</p>
     <div class="example-contents screen">
         <div class="cdata"><pre>
First parsed output is tm_sec : 0 , tm_min : 0 , tm_hour : 16 , tm_year : 1969 , 
tm_mday : 31 , tm_wday : 4 , tm_yday : 365 , tm_mon : 11 , tm_isdst : 0 , 
</pre></div>
     </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-intldateformatter.localtime-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
    <ul class="simplelist">
    <li class="member"><span class="function"><a href="intldateformatter.create.html" class="function" rel="rdfs-seeAlso">datefmt_create()</a> - Create a date formatter</span></li>
    <li class="member"><span class="function"><a href="intldateformatter.format.html" class="function" rel="rdfs-seeAlso">datefmt_format()</a> - Format the date/time value as a string</span></li>
    <li class="member"><span class="function"><a href="intldateformatter.parse.html" class="function" rel="rdfs-seeAlso">datefmt_parse()</a> - Parse string to a timestamp value</span></li>
    <li class="member"><span class="function"><a href="intldateformatter.geterrorcode.html" class="function" rel="rdfs-seeAlso">datefmt_get_error_code()</a> - Get the error code from last operation</span></li>
    <li class="member"><span class="function"><a href="intldateformatter.geterrormessage.html" class="function" rel="rdfs-seeAlso">datefmt_get_error_message()</a> - Get the error text from the last operation</span></li>
    </ul>
  </p>
 </div>

</div></div></div></body></html>